#ifndef JOINT_BOOSTING_TEST_H_
#define JOINT_BOOSTING_TEST_H_

#include "JointBoosting.h"

GLOBAL_NAMESPACE_BEGIN

namespace FileTools
{
    class XmlParser;
}

namespace MachineLearningTest
{
    class JBTest
    {
    public:
        struct DataGeneratorOptions
        {
            bool bRun;
            std::string outputFileName;
            std::string outputPredName;
            int sampleSize;
            int classSize;
            std::vector<double> sampleCenters;
        };
        struct InputOptions
        {
        };
    public:
        static void generateXMLTemplate(const char* fileName);
        static void generateTestData();
        static void generatePredictLabel();
        static void test0();
        static void test1();

        static double validate(const Eigen::MatrixXi& inputPred, const Eigen::MatrixXi& predictMat);

        static void saveJointBoostingToObjFile(const char* fileName, const MLAlgorithms::JointBoosting& jbAlgo);

        static int  getType(const std::string& type);
        static void getDataFileNames(const char* inFileName, const std::string& folderName, std::vector<std::string>& fileNames);
        static void run(const char* xmlFileName);

    private:
        static void runParam(FileTools::XmlParser* xml, const std::string& childName);
        static void runTest (FileTools::XmlParser* xml, const std::string& childName);
        static void runFragGen   (FileTools::XmlParser* xml, const std::string& childName);
        static void runFragSave  (FileTools::XmlParser* xml, const std::string& childName);
        static void runFeatureGen(FileTools::XmlParser* xml, const std::string& childName);
        static void runPrepareData(FileTools::XmlParser* xml, const std::string& childName);
        static void runFeatureSel(FileTools::XmlParser* xml, const std::string& childName);
        static void runTraining  (FileTools::XmlParser* xml, const std::string& childName);

    public:
        static DataGeneratorOptions dgOpts_;
        
        static const char* runType[];
        static const char* Attributes[];

        enum RunTypes {
            XML_ML_JB_RUN_PARAMETER = 0,
            XML_ML_JB_RUN_TEST,
            XML_ML_JB_RUN_FRAGMENT_GEN,
            XML_ML_JB_RUN_FRAGMENT_SAVE,
            XML_ML_JB_RUN_FEATURE_GEN,
            XML_ML_JB_RUN_TRAINING,
            XML_ML_JB_RUN_TRAINING_PREPAREDATA,
            XML_ML_JB_RUN_TRAINING_FEA_SELECT
        };

        enum Attribute {
            XML_ML_JB_TYPE = 0,
            XML_ML_JB_RUN = 1,
            ////////////////////////XML_ML_JB_RUN_PARAMETER
            XML_ML_JB_PARA_OUTPUT_FILENAME = 2,
            XML_ML_JB_PARA_OUTPUT_PREDNAME,
            XML_ML_JB_PARA_SAMPLE_SIZE,
            XML_ML_JB_PARA_SAMPLE_CLASS,
            XML_ML_JB_PARA_SAMPLE_CENTERS,
            ////////////////////////XML_ML_JB_RUN_TEST
            XML_ML_JB_TEST_INPUT_FILENAME ,
            XML_ML_JB_TEST_INPUT_LABELNAME,
            XML_ML_JB_TEST_OUTPUT_LABELNAME,
            XML_ML_JB_TEST_TRAINING_ROUND,
            XML_ML_JB_TEST_STEP_SIZE,
            XML_ML_JB_TEST_OUTPUT_MODELNAME,
            ////////////////////////XML_ML_JB_RUN_FRAGMENT_GEN
            XML_ML_JB_FRAGGEN_INPUT_FILENAME ,
            XML_ML_JB_FRAGGEN_INPUT_FOLDER,
            XML_ML_JB_FRAGGEN_SAMPLE_SIZE,
            XML_ML_JB_FRAGGEN_SAVE_IMAGE,
            XML_ML_JB_FRAGGEN_OUTPUT_FOLDER,
            XML_ML_JB_FRAGGEN_OUTPUT_FRAGNAME,
            ////////////////////////XML_ML_JB_RUN_FRAGMENT_SAVE
            XML_ML_JB_FRAGSAV_INPUT_FILENAME,
            XML_ML_JB_FRAGSAV_INPUT_FOLDER,
            ////////////////////////XML_ML_JB_RUN_FEATURE_GEN
            XML_ML_JB_FEATUREGEN_INPUT_FILENAME,
            XML_ML_JB_FEATUREGEN_TEST_IMAGE,
            XML_ML_JB_FEATUREGEN_OUTPUT_FOLDER,
            ////////////////////////XML_ML_JB_RUN_TRAINING
            XML_ML_JB_TRAINING_INPUT_FILENAME,
            XML_ML_JB_TRAINING_INPUT_FOLDER,
            XML_ML_JB_TRAINING_INPUT_FEATUREGEN,
            XML_ML_JB_TRAINING_INPUT_FEATURE_FOLDER,
            XML_ML_JB_TRAINING_INPUT_FEATURE_LIST,
            XML_ML_JB_TRAINING_INPUT_LABEL_FILE,
            XML_ML_JB_TRAINING_ROUND,
            XML_ML_JB_TRAINING_STEP_SIZE,
            XML_ML_JB_TRAINING_OUTPUT_MODEL,
            XML_ML_JB_TRAINING_OUTPUT_FOLDER,
            XML_ML_JB_TRAINING_OUTPUT_LABEL,
            ////////////////////////XML_ML_JB_RUN_TRAINING_PREPAREDATA
            XML_ML_JB_TRAINING_PRE_INPUT_FILENAME,
            XML_ML_JB_TRAINING_PRE_INPUT_FOLDER,
            XML_ML_JB_TRAINING_PRE_INPUT_FEATUREGEN,
            XML_ML_JB_TRAINING_PRE_SAVE_FEATUREIMG,
            XML_ML_JB_TRAINING_PRE_OUTPUT_FEATURE_FOLDER,
            XML_ML_JB_TRAINING_PRE_OUTPUT_MODEL,
            ////////////////////////XML_ML_JB_RUN_TRAINING_FEA_SELECT
            XML_ML_JB_TRAINING_FEASEL_INPUT_FILENAME,
            XML_ML_JB_TRAINING_FEASEL_INPUT_FOLDER,
            XML_ML_JB_TRAINING_FEASEL_INPUT_FEATUREGEN,
            XML_ML_JB_TRAINING_FEASEL_INPUT_FEAGEN_FOLDER,
            XML_ML_JB_TRAINING_FEASEL_ROUND,
        };
    };
}

GLOBAL_NAMESPACE_END

#endif//JOINT_BOOSTING_TEST_H_